<template>
    <div>
        <van-form @submit="onSubmit">
            <van-cell-group inset>
                <van-field v-model="userName" name="userName" label="用户名" placeholder="用户名"
                    :rules="[{ pattern, message: '请填写用户名' }]" />
                <van-field v-model="userPwd" type="password" name="userPwd" label="密码" placeholder="密码"
                    :rules="[{ pattern, message: '请填写密码' }]" />
            </van-cell-group>
            <div style="margin: 16px;">
                <van-button round block type="primary" native-type="submit">
                    提交
                </van-button>
            </div>
        </van-form>
    </div>
</template>

<script setup lang='ts'>
import { ref } from 'vue';
import { loginapi } from '@/api/http'
import { useRouter } from 'vue-router';
import { useStore } from 'vuex';

const router = useRouter()
const userName = ref('');
const userPwd = ref('');
const pattern = /\d{6}/;
const onSubmit = (values: any) => {
    console.log('submit', values);
    loginapi(values).then((res: any) => {
        console.log('denglu', res);
        if (res.responseCode == 0) {
            router.push('/home')
            localStorage.setItem('user_code', res.user_code)
            localStorage.setItem('userName', userName.value)
        }

    })
};
</script>
<style scoped>

</style>